package com.vip.jwt.controller;


import com.vip.jwt.common.entity.R;
import com.vip.jwt.entity.Role;
import com.vip.jwt.service.UserRoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户角色关联表 前端控制器
 * </p>
 *
 * @author vip
 * @since 2021-05-04
 */
@RestController
@RequestMapping("/api/user/role")
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;

    @GetMapping("/{userId}")
    public Object findByUserId(@PathVariable String userId){
        List<Role> roles = userRoleService.findByUserId(userId);
        List<String> roleIds = roles.stream()
                .map(Role::getId).collect(Collectors.toList());
        return R.ok().data("data",roleIds);
    }

}

